package baseFx.tests.common.caching.redis;

import baseFx.common.caching.redis.RedisMapCache;
import baseFx.common.collections.RemoteMap;
import baseFx.common.concurrent.Task;
import baseFx.serialization.json.JsonUtils;
import redis.clients.jedis.Jedis;

import java.util.Date;
import java.util.UUID;

public class TestRedisMapCache {
    public static void main(String[] args) {
        Jedis jedis = new Jedis();
        jedis.auth(Config.redis_password);
        RemoteMap<Model> map = new RedisMapCache<>(jedis, Model.class, UUID.randomUUID().toString(), 2);
        Model m = new Model();
        m.id = 1;
        m.name = "aaa";
        m.time = new Date();
        map.put("a", m);
        m.id = 2;
        m.name = "bbb";
        m.time = new Date(System.currentTimeMillis() + 1000);
        map.put("b", m);
        m.id = 3;
        m.name = "ccc";
        m.time = new Date(System.currentTimeMillis() + 2000);
        map.put("c", m);
        System.out.println(JsonUtils.toJson(map.get("a")));
        System.out.println(JsonUtils.toJson(map.get("b")));
        System.out.println(JsonUtils.toJson(map.get("c")));
        Task.delay(2000);
        System.out.println(map.size());
    }

    private static class Model {
        public Integer id;
        public String name;
        public Date time;
    }
}
